﻿@model Think9.Models.TbBasicEntity
@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<input style="display: none" name="id" id="id">
<input style="display: none" name="FlowId" id="FlowId" value="@Model.FlowId">
<form class="layui-form" lay-filter="formEdit">
    <div class="layui-form-item">
        <label class="layui-form-label">子表编码</label>
        <div class="layui-input-block">
            <input type="text" name="TbId" id="TbId" placeholder="子表编码" autocomplete="off" class="layui-input" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">子表名称</label>
        <div class="layui-input-block">
            <input type="text" name="TbName" id="TbName" placeholder="子表名称" autocomplete="off" class="layui-input" lay-verify="required" maxlength="30">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序号</label>
        <div class="layui-input-block">
            <input type="text" name="OrderNo" id="OrderNo" placeholder="排序号" autocomplete="off" class="layui-input" maxlength="3" lay-verify="required|number">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">数据初始化</label>
        <div class="layui-input-block">
            <input type="text" name="TBRelation" id="TBRelation" placeholder="" autocomplete="off" class="layui-input" readonly="readonly">
            <span style="position: absolute;bottom: 6px; right: 5px;">
                <a href="javascript:;"><i class="fa fa-check-circle" id="editR">编辑</i></a>
            </span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备 注</label>
        <div class="layui-input-block">
            <textarea placeholder="" value="" name="TbExplain" id="TbExplain" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> </label>
        <div class="layui-input-block">
            <input type="hidden" name="InType" value="0">
            <input type="checkbox" name="InType" id="InType" lay-skin="primary" title="可动态添加删除行(包含增加和删除按钮,可单独增加删除行)" value="1" lay-filter="InType">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="edit">编辑</button>
        </div>
    </div>
</form>

<script>
	layui.use(["table", 'form', "exLayer", "exUtils"], function () {
		let form = layui.form;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let table = layui.table;

		let $ = layui.$;

		getFormVal();

		//给表单赋值
		form.val("formEdit", {
			"TbId": "@Model.TbId",
			"TbName": "@Model.TbName",
			"OrderNo": "@Model.OrderNo",
			"TbExplain": "@Model.TbExplain"
		});

		function getFormVal() {
			if (@Model.InType == "1") {
				$('#InType').attr("checked", true);
			}
			else {
				$("#InType").removeAttr("checked");
			}
		}

		form.on("submit(edit)", function (data) {
            exUtils.ajax("/SysTable/TbBasic/Edit02", "post", { model: data.field, fwid: $("#FlowId").val()}, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
			}).fail(function (error) {
				console.log(error);
			});
			return false;
        });

        $("#editR").click(function () {
            exLayer.open($("#TbName").val() + "--子表数据初始化", "/SysTable/TbRelation/List?tbid=" + $("#TbId").val(), '100%', '100%', '0px', '0px', null, null);
        });
        $("#TBRelation").click(function () {
            exLayer.open($("#TbName").val() + "--子表数据初始化", "/SysTable/TbRelation/List?tbid=" + $("#TbId").val(), '100%', '100%', '0px', '0px', null, null);
        });
	})
</script>